class_name DeckSrc
extends Resource

signal deckSizeChanged(cardsNum)

@export var cards:Array[CardSrc]=[]

func isEmpty()->bool:
    return cards.is_empty()

# 抽卡
func draw()->CardSrc:
    var card=cards.pop_front()
    deckSizeChanged.emit(cards.size())
    return card

# 添加卡牌
func addCard(card:CardSrc):
    cards.append(card)
    deckSizeChanged.emit(cards.size())

func shuffle()->void:
    cards.shuffle()

func clear()->void:
    cards.clear()
    deckSizeChanged.emit(cards.size())

func _to_string()->String:
    var _card_string:PackedStringArray=[]
    for i in range(cards.size()):
        _card_string.append("%s:%s" % [i+1,cards[i].id])

    return "\n".join(_card_string)
